#include "ueq_eq.h"
#include <string.h>

void ueq_event_queue_test_1_element(void)
{
    UeqEventQueue eq;
    BYTE buffer[2];
    UeqEvent event = 0;

    /*  Init test
        start:  []
        end:    [..]
    */
    ueq_event_queue_init(&eq, buffer, 2);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq));
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST0) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST9) == FALSE);

    /*  Push back test
        start:  [..]
        end:    [4.]
    */
    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST4);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq));
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST4));

    /*  Pop front test
        start:  [4.]
        end:    [..]
    */
    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST4);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq));
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST4) == FALSE);

    /*  Push back with wrap around test
        start:  [..]
        end:    [.5]
    */
    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST5);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq));
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST5));

    /*  Pop front test
        start:  [.5]
        end:    [..]
    */
    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST5);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq));
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST5) == FALSE);

    /*  Reset test
        start:  [..]
        end:    []
    */
    ueq_event_queue_reset(&eq);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == TRUE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST4) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST5) == FALSE);
}

void ueq_event_queue_test_5_elements(void)
{
    UeqEventQueue eq;
    BYTE buffer[6];
    UeqEvent event = 0;

    /*  Init test
        start:  []
        end:    [......]
    */
    ueq_event_queue_init(&eq, buffer, 6);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == TRUE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST0) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST9) == FALSE);

    /*  Push back test
        start:  [......]
                [4.....]
                [45....]
                [456...]
                [4567..]
        end:    [45678.]
    */
    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST4);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST4));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST5);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST5));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST6);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST6));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST7);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST7));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST8);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq));
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST8));

    /*  Pop front test
        start:  [45678.]
                [.5678.]
                [..678.]
                [...78.]
                [....8.]
        end:    [......]
    */
    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST4);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST4) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST5);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST5) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST6);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST6) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST7);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST7) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST8);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq));
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST8) == FALSE);

    /*  Push back test with wrap around
        start:  [......]
                [.....9]
                [0....9]
                [01...9]
                [012..9]
        end:    [0123.9]
    */
    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST9);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST9));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST0);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST0));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST1);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST1));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST2);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST2));

    ueq_event_queue_push_back(&eq, UEQ_EVENT_TEST3);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq));
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST3));

    /*  Pop front test with wrap around
        start:  [0123.9]
                [0123..]
                [.123..]
                [..23..]
                [...3..]
        end:    [......]
    */
    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST9);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST9) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST0);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST0) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST1);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST1) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST2);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST2) == FALSE);

    event = ueq_event_queue_pop_front(&eq);
    UEQ_ASSERT(event == UEQ_EVENT_TEST3);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq));
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST3) == FALSE);

    /*  Reset test
        start:  [......]
        end:    []
    */
    ueq_event_queue_reset(&eq);
    UEQ_ASSERT(ueq_event_queue_is_empty(&eq));
    UEQ_ASSERT(ueq_event_queue_is_full(&eq) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST9) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST0) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST1) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST2) == FALSE);
    UEQ_ASSERT(ueq_event_queue_contains(&eq, UEQ_EVENT_TEST3) == FALSE);
}
